package com.common.help.test14;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

import com.common.help.test14.Outter.Inner;

public class TestA {

	
	public static void main(String[] args) {
		int rank = 1;
		
		List<Student> list = new ArrayList<>();
		Student s = new Student();
		s.setAge(10);
		s.setName("1");
		list.add(s);
		Student ss = new Student();
		ss.setAge(20);
		ss.setName("2");
		list.add(ss);
		Student sss = new Student();
		sss.setAge(10);
		sss.setName("3");
		list.add(sss);
		Student ssss = new Student();
		ssss.setAge(20);
		ssss.setName("4");
		list.add(ssss);
		
		Student sssss = new Student();
		sssss.setAge(30);
		sssss.setName("5");
		list.add(sssss);
		
		Collections.sort(list, new Comparator<Student>() {

			@Override
			public int compare(Student o1, Student o2) {
				if(o1.getAge()>o2.getAge()){
					return -1;
				}else{
					return 1;
				}
			}
		});
		for(int i=0;i<list.size();i++){
			if(i==0){
				Student st = list.get(i);
				st.setRank(rank);
				System.out.println(st.toString());
				continue;
			}
			Student before = list.get(i-1);
			Student after = list.get(i);
			if(before.getAge()>after.getAge()){
				rank = rank +1;
			}
			after.setRank(rank);
			System.out.println(after.toString());
		}
		
		for(Student st1 : list){
			test(st1.getAge());
		}
		
	}
	
	public static void test(int i){
		if(i==10){
			System.out.println(i);
			return;
		}
		//System.out.println(i);
	}
}

class Student{
	private int rank;
	private int age;  
    private String name;  
    
    
    public int getRank() {
		return rank;
	}

	public void setRank(int rank) {
		this.rank = rank;
	}

	public int getAge() {  
        return age;  
    }  
  
    public void setAge(int age) {  
        this.age = age;  
    }  

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

	@Override
	public String toString() {
		return "Student [rank=" + rank + ", age=" + age + ", name=" + name + "]";
	}

}

class Outter{
	
	private Inner inner=  null;
	
	private int i;
	private String ii;
	
	public Outter(int i,String ii){
		this.i = i;
		this.ii = ii;
	}
	
	public Inner getInstantce(){
		if(inner==null){
			System.out.println("inner对象为空 需要new");
		}
		inner = new Inner(this.i,this.ii);
		return  inner;
	}
	
	class Inner{
		
		private int a;
		private String aa;
		
		private List<String> list = new LinkedList<>();
		public Inner(int a,String aa){
			this.a = a;
			this.aa = aa;
			i = a;
			ii = aa;
			list.add(aa);
		}
		
		public int getA(){
			try {
				this.a = Integer.valueOf(aa)+a;
			} catch (NumberFormatException e) {
				throw new RuntimeException("出现异常啦  转换不过来"+aa);
			}
			return a;
		}
		
		public List<String> getList(){
			return list;
		}
		
		public void clear(){
			list.clear();
		}
	}
}